var UserTutorConsult = app.controller('UserTutorConsult', function($rootScope,$stateParams, $scope, $http,$state,$timeout,$cordovaDevice,$cordovaChat,UserTutorConsultData) {
	try{
		$rootScope.showf=false;
		$scope.busy = false;
		
		$scope.currentPage = 1;
		$scope.limit = 10;
		$scope.pages = 1;
		
		$scope.title="成功案例";
		$scope.info={};
		var url=SITE_URL+"index.php?app=baseloginapp&act=tutorconsult&callback=JSON_CALLBACK&id="+$stateParams.id;
		$http.jsonp(url).success( function(data) {
			if(data.done){
				$scope.info=data.retval.data;
				$scope.pages = Math.ceil(data.retval.total
						/ $scope.limit);
				$scope.busy = false;
			}
		});	
		
		$scope.closeAlert = function(index) {
			$scope.alerts.splice(index, 1)
		}
		//加载更多
		$scope.loadMore = function() {
			if ($scope.currentPage < $scope.pages) {
				if ($scope.busy) {
					return false;
				}
				$scope.busy = true;
				$scope.currentPage++;
				var url = SITE_URL
				+ "index.php?app=baseloginapp&act=tutorconsult&callback=JSON_CALLBACK"+"&page="+$scope.currentPage+"&id="+$stateParams.id;
				$http.jsonp(url).success(
						function(data) {
							if (data.done) {
								for ( var i in data.retval.data) {
									if (typeof data.retval.data[i] != "function")
										$scope.info.push(data.retval.data[i]);
								}
								$scope.pages = Math.ceil(data.retval.total
										/ $scope.limit);
								$scope.busy = false;
								if ($scope.pages <= $scope.currentPage) {
									$scope.alerts = [ {
										type : 'success',
										msg : '没有更多内容了'
									} ]
								}
							}
						});
			}
		};
	}
	catch (e) {
		showcatch(e);
	}
});
UserTutorConsult.UserTutorConsultData=function($q, $http,$stateParams,$rootScope){
	try {
		var data = [];
		var def = $q.defer();
		if(window.localStorage.u==undefined||window.localStorage.u==null||window.localStorage.u==""){			
			$rootScope.go("loginmain");
		}else{
			def.resolve(data);
		}
		
		return def.promise;
	} catch (e) {
		showcatch(e);
	}
}